package com.ywy.dao;

import com.ywy.entity.UserDownload;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 用户下载Repository接口
 *
 * @author ywy
 * @date 2022/9/8 13:40
 */
public interface UserDownloadDao extends JpaRepository<UserDownload, Integer>, JpaSpecificationExecutor<UserDownload> {
    /**
     * 查询某个用户下载某个资源的次数
     *
     * @param userId
     * @param resId
     * @return
     */
    @Query(value = "select count(*) from sys_user_download where user_id=?1 and res_id=?2", nativeQuery = true)
    int getCountByUserIdAndResId(Integer userId, Integer resId);

    /**
     * 删除指定资源的下载信息
     * @param resId
     */
    @Modifying
    @Query(value = "delete from sys_user_download where res_id=?1", nativeQuery = true)
    void deleteByResId(Integer resId);
}
